//
//  Macro.h
//  HeaderMacro
//
//  Created by Burn on 2019/5/30.
//  Copyright © 2019 menksoft. All rights reserved.
//

#ifndef Macro_h
#define Macro_h
#import <UIKit/UIKit.h>

//$(SRCROOT)

#ifdef DEBUG
#define MKLog(fmt, ...) NSLog((@"[DEBUG] %@ [Line %d]--> " fmt), [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, ##__VA_ARGS__)
#else
#define MKLog(fmt, ...)
#endif

#define MKTabBarHeight 60.0

#define keyboard_settings_key @"group.com.menk.keys.settings"
#define keyboard_user_defaults [[NSUserDefaults standardUserDefaults]initWithSuiteName:keyboard_settings_key]
/**是否是大写*/
#define IS_UPPERCASE @"IS_UPPERCASE"
/**是否是数字键盘*/
#define IS_NUMBERCASE @"IS_NUMBERCASE"

#define MKImg(name) [UIImage imageNamed:name inBundle:[NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"MKOrdosMedia" ofType:@"bundle"]] compatibleWithTraitCollection:nil]

/// 播放器view的tag，列表中UI控件唯一tag值
#define kPlayerViewTag 100


// 删除所有内容吗?
#define kMKCLEAN @"     "

/// 字体
//#define MenkQaganStdExTig(x)          [UIFont fontWithName:@"MenkQaganStdExTig" size:x]
#define MenkQaganTig(x)          [UIFont fontWithName:@"Menk Qagan Tig" size:x]

/// 用户是否已登录
#define MK_SET_USER_LOGIN(value) [[NSUserDefaults standardUserDefaults] setBool:value forKey:@"MK_USR_LOGIN"]; \
[[NSUserDefaults standardUserDefaults] synchronize];
/// 获取是否登录
#define MK_GET_USR_STATUS [[NSUserDefaults standardUserDefaults]boolForKey:@"MK_USR_LOGIN"]


// 首页四个按钮点击通知
#define MK_HOME_BTN_CLICK @"MK_HOME_BTN_CLICK"

// 请同意用户协议
#define MK_PROTOCL_MSG @" \n \n"

/// 手机号错误
#define MK_PNUM_ERROR @" \n \n"

/// 验证码错误
#define MK_CODE_ERROR @" \n \n"

/// 请输入密码
#define MK_INSERT_PASS @" \n \n"

// 短信发送成功
#define MK_SEND_MSG_OK @" \n \n \n"

// 短信发送失败
#define MK_SEND_MSG_ERROR @"\n"

// 网络错误
#define MK_NETWORK_ERROR @" \n \n"

// 功能未开启
#define MK_FUNCTION_NO @" \n  \n "

// 请登录
#define MK_GOTO_LOGIN @" "


#define MK_NOT_LOGIN @" ︕"

// MARK: 发送给控制器
#define MK_NOTIFICATION_SUBVC @"MK_NOTIFICATION_SUBVC"


// 保存用户信息Key
#define MK_USER @"MKUSER"

/// 登录 - 添加用户信息
#define SaveCustomModelToUserDefaults(data) \
do { \
    [[NSUserDefaults standardUserDefaults] setObject:data forKey:MK_USER]; \
    [[NSUserDefaults standardUserDefaults] synchronize]; \
} while(0)


/// 退出登录 - 删除用户信息
#define RemoveCustomModel \
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:MK_USER]; \
    [[NSUserDefaults standardUserDefaults] synchronize];


// MKUserModel 获取用户信息
#define MK_USER_GET [NSKeyedUnarchiver unarchiveObjectWithData:[[NSUserDefaults standardUserDefaults]objectForKey:MK_USER]]


#define MKpageSize 20


// 下拉刷新
#define MK_REFRESH_PULL @" \n \n"

// 松开刷新
#define MK_REFRESH_RELEASE @" \n"

//正在刷新
#define MK_REFRESH_REFRESHING @" \n᠁"

// 上拉加载
#define MK_LOAD_PULL @" \n \n"
// 松开加载
#define MK_LOAD_RELEASE @" \n \n \n \n \n"
// 正在加载
#define MK_LOAD_LOADING @" \n᠁"
// 已全部加载完毕
#define MK_LOAD_NO_MORE @" \n \n \n \n"


// 成功保存到相册
#define MK_SAVE_IMG_SUCCESS @" \n \n \n"

//保存到相册失败
#define MK_SAVE_IMG_FAIL @" \n \n \n \n \n"

//复制链接成功
#define MK_COPY_URL_SUCCESS @" \n"




#define default_item_height 120



//  播放相关的通知
//  播放状态变化
#define PLAYSTATUCHANGEKEY @"PLAYSTATUCHANGEKEY"
//  全屏点击
#define FULLSCREENCLICK @"FULLSCREENCLICK"
//  URL不支持断点下载-1002
#define URLNAGETIVE1002 @"URL-1002"
//  右上方按钮点击
#define RiGHTTOPCLICK @"RiGHTTOPCLICK"
//  播放器返回按钮点击
#define PLAYBACK @"PLAYBACK"


// 屏幕宽高
#define SCREEN_HEIGHT   [UIScreen mainScreen].bounds.size.height
#define SCREEN_WIDTH   [UIScreen mainScreen].bounds.size.width

#define CURRENT_SIZEWIDTH(_size) _size*SCREEN_WIDTH / 375.0
#define CURRENT_SIZEHEIGHT(_size) _size*SCREEN_HEIGHT / 667.0

//PlaceHolderImg
#define PlaceHolderImg  [UIImage imageNamed:@"testImg"]


/**
 * Macro For Color
 */
#pragma mark - Color
#define MK_BLACK(alpha) [[UIColor blackColor] colorWithAlphaComponent:alpha]
#define MK_WHITE(alpha) [[UIColor whiteColor] colorWithAlphaComponent:alpha]
#define MK_CLEAR [UIColor clearColor]
#define MK_COLOR(colorName,alpha) [[UIColor colorName] colorWithAlphaComponent:alpha]
#define MK_COLOR_Alpha(color,alpha) [color colorWithAlphaComponent:alpha]
#define MK_RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
#define MK_HEXCOLOR(hexCode) [UIColor colorWithRed:((hexCode>>16)&0xFF)/255.0 green:((hexCode>>8)&0xFF)/255.0 blue:((hexCode)&0xFF)/255.0 alpha:1.0]
#define MK_HEXCOLOR_Alpha(hexCode,alpha) [[UIColor colorWithRed:((hexCode>>16)&0xFF)/255.0 green:((hexCode>>8)&0xFF)/255.0 blue:((hexCode)&0xFF)/255.0 alpha:1.0] colorWithAlphaComponent:alpha]

#define RGBACOLOR(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)]
#define MK_RANDOMCOLOR [UIColor colorWithRed:arc4random_uniform(255) / 255.0 green:arc4random_uniform(255) / 255.0 blue:arc4random_uniform(255) / 255.0 alpha:1]

#define MK_SHARE_TITLE @"ᠳᠤᠯᠠᠭᠠᠨ ᠬᠣᠲᠠ ᠣᠷᠳᠣᠰ  ᠤᠨ ᠲᠠᠭᠤᠨ  ᠢ ᠤᠯᠠᠮᠵᠢᠯᠠᠨ ᠳᠠᠮᠵᠢᠭᠤᠯᠤᠶ᠎ᠠ︕"

/**
 * Macro For Font
 */
#pragma mark - Font
#define PJ_FONT [UIFont fontWithName:@"PingFangSC-Regular"]
#define MK_FONT(size) [UIFont systemFontOfSize:size]
#define MK_BOLDFONT(size) [UIFont boldSystemFontOfSize:size]
#define MK_FONT_N(fontName,fontSize) [UIFont fontWithName:fontName size:fontSize]


//程序全局委托
#define appDelegate   ((AppDelegate *)[[UIApplication sharedApplication] delegate])
//UserDefaults
#define UserDefaults [NSUserDefaults standardUserDefaults]
//语言设置
#define KSetLanguage(x)                     [[NSUserDefaults standardUserDefaults]setObject:(x) forKey:@"use_language"]
#define KGetLanguage                        [[NSUserDefaults standardUserDefaults]stringForKey:@"use_language"]
#define KIsChinese                          [KGetLanguage isEqualToString:@"cn"]
#define KIsMn                               [KGetLanguage isEqualToString:@"mn"]

#define Img(img)                            [UIImage imageNamed:img]
#define Url(url)                            [NSURL URLWithString:url]



//蒙科立字体
#define MenksoftQagan_mirror(x)          [UIFont fontWithName:@"MenksoftQagan_mirror" size:x] //蒙科立镜像字体
#define HvrStudioChaganTig_M(x)          [UIFont fontWithName:@"HvrStudioChaganTig-M" size:x] //标准编码使用
#define MenkTransform                    CGAffineTransformConcat(CGAffineTransformMakeRotation(M_PI_2), CGAffineTransformMake(-1, 0, 0, 1, 0, 0))
#define MenkRotation                     CGAffineTransformMakeRotation(M_PI_2)


//iPhone_X
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_IOS_11  ([[[UIDevice currentDevice] systemVersion] floatValue] >= 11.f)
#define IS_IPHONE_X (IS_IOS_11 && IS_IPHONE && (MIN([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) >= 375 && MAX([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) >= 812))

// iPhone5 iPhone5s iPhoneSE
#define IS_iPhone_5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)

// iPhone6 7 8
#define IS_iPhone_6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? (CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) || CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size)) : NO)

// iPhone6plus  iPhone7plus iPhone8plus
#define IS_iPhone6_Plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? (CGSizeEqualToSize(CGSizeMake(1125, 2001), [[UIScreen mainScreen] currentMode].size) || CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size)) : NO)

// iPhoneX
#define IS_iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)

// iPhoneXR
#define IS_iPhoneXR ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(828, 1792), [[UIScreen mainScreen] currentMode].size) : NO)

// iPhoneXS Max
#define IS_iPhoneXSMax ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2688), [[UIScreen mainScreen] currentMode].size) : NO)

#define SafeAreaTopHeight (SCREEN_HEIGHT >= 812.0 ? 88 : 64)
#define SafeAreaBottomHeight (SCREEN_HEIGHT >= 812.0 ? 34 : 0)
#define SafeAreaStatuBarHeight (SCREEN_HEIGHT >= 812.0 ? 44 : 20)
#define SafeAreaValueHeight (SCREEN_HEIGHT >= 812.0 ? 24 : 0)
#define SafeAreaLiuHiaHeight (SCREEN_HEIGHT >= 812.0 ? 30 : 0)

//DEBUG操作
#ifdef DEBUG
#define DLOG(...)   NSLog(__VA_ARGS__)
#define DLOGPOINT(p)    NSLog(@"%f,%f", p.x, p.y);
#define DLOGSIZE(size)    NSLog(@"%f,%f", size.width, size.height);
#define DLOGRECT(p)    NSLog(@"%f,%f %f,%f", p.origin.x, p.origin.y, p.size.width, p.size.height);
#else
#define DLOG(...)
#define DLOGPOINT(p)
#define DLOGSIZE(p)
#define DLOGRECT(p)
#endif

#define IOS8            ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 8.0)
//是否为ios9
#ifndef IOS9
#define IOS9            ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0?YES:NO)
#endif


#pragma mark - Tools methods
/**
 *  判断一个对象是否为空
 *
 *  @param thing 对象
 *
 *  @return 返回结果
 */
static inline BOOL ICIsObjectEmpty(id thing){
    return thing == nil ||
    ([thing isEqual:[NSNull null]]) ||
    ([thing respondsToSelector:@selector(length)] && [(NSData *)thing length] == 0) ||
    ([thing respondsToSelector:@selector(count)]  && [(NSArray *)thing count] == 0);
}

/**
 *  判断一个字符串是否为空
 *
 *  @param string 字符串
 *
 *  @return 返回结果
 */
static inline BOOL ICIsStringEmpty(NSString *string){
    
    if (![string isKindOfClass:[NSString class]]) {
        
        string = [NSString stringWithFormat:@"%@",string];
    }
    
    if (string == nil) {
        return YES;
    }
    
    if (string.length == 0) {
        return YES;
    }
    
    if ([string isEqualToString:@"<null>"]) {
        return YES;
    }
    
    if ([string isEqualToString:@"(null)"]) {
        return YES;
    }
    
    return NO;
}

/**
 *  弱引用对象
 *
 *  @param self 当前对象
 *
 *  @return 弱应用对象
 */
#define WEAKSELF typeof(self) __weak weakSelf = self;

/**
 *  强引用对象
 *
 *  @param self 当前对象
 *
 *  @return 强引用对象
 */
#define STRONGSELF typeof(self) __strong strongSelf = self;

#endif /* Macro_h */




//条件编译
#if __has_feature(objc_arc)
//ARC

//#define IMSingletonH(name) + (instancetype)shared##name;
//+ (instancetype)shared##name{\

//.h头文件中的单例宏  sharedRemotePlayerFileManager
#define IMSingletonH + (instancetype)shared;

//.m文件中的单例宏
#define IMSingletonM \
static id _instance;\
+ (instancetype)allocWithZone:(struct _NSZone *)zone{\
static dispatch_once_t onceToken;\
dispatch_once(&onceToken, ^{\
_instance = [super allocWithZone:zone];\
});\
return _instance;\
}\
+ (instancetype)shared{\
static dispatch_once_t onceToken;\
dispatch_once(&onceToken, ^{\
_instance = [[self alloc] init];\
});\
return _instance;\
}\
- (id)copyWithZone:(NSZone *)zone{\
return _instance;\
}



#else
//MRC


//.h头文件中的单例宏
#define IMSingletonH(name) + (instancetype)shared##name;

//.m文件中的单例宏
#define IMSingletonM(name) \
static id _instance;\
+ (instancetype)allocWithZone:(struct _NSZone *)zone{\
static dispatch_once_t onceToken;\
dispatch_once(&onceToken, ^{\
_instance = [super allocWithZone:zone];\
});\
return _instance;\
}\
+ (instancetype)shared##name{\
static dispatch_once_t onceToken;\
dispatch_once(&onceToken, ^{\
_instance = [[self alloc] init];\
});\
return _instance;\
}\
- (id)copyWithZone:(NSZone *)zone{\
return _instance;\
}\
- (oneway void)release{\
}\
- (instancetype)retain{\
return self;\
}\
- (NSUInteger)retainCount{\
return 1;\
}\
- (instancetype)autorelease{\
return self;\
}



#endif
